package com.henry.chatkit.messages.holder

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.ToastUtils
import com.henry.chatkit.R
import com.henry.chatkit.messages.MessageInfo
import com.henry.chatkit.MessageStatus

class MessageFileHolder(itemView: View) : MessageContentHolder(itemView) {

    private lateinit var fileNameText: TextView
    private lateinit var fileSizeText: TextView
    private lateinit var fileStatusText: TextView
    private lateinit var fileIconImage: ImageView

    override fun getVariableLayout(): Int {
        return R.layout.message_content_file
    }

    override fun initVariableViews() {
        fileNameText = rootView.findViewById(R.id.file_name_tv)
        fileSizeText = rootView.findViewById(R.id.file_size_tv)
        fileStatusText = rootView.findViewById(R.id.file_status_tv)
        fileIconImage = rootView.findViewById(R.id.file_icon_iv)
    }

    override fun layoutVariableViews(msg: MessageInfo?, position: Int) {

        if (msg == null) {
            return
        }

        val path: String = ""
        fileNameText.text = "FileName"
        fileSizeText.text = "20M"
        msgContentFrame.setOnClickListener { ToastUtils.showShort("文件路径:$path") }
        if (msg.isSelf) {
            if (msg.status == MessageStatus.SENDING) {
                fileStatusText.setText(R.string.sending)
            } else if (msg.status == MessageStatus.SEND_SUCCESS || msg.status == MessageStatus.NORMAL) {
                fileStatusText.setText(R.string.sended)
            }
        } else {
            if (msg.status == MessageStatus.DOWNLOADING) {
                fileStatusText.setText(R.string.downloading)
            } else if (msg.status == MessageStatus.DOWNLOADED) {
                fileStatusText.setText(R.string.downloaded)
            } else if (msg.status == MessageStatus.UN_DOWNLOAD) {
                fileStatusText.setText(R.string.un_download)
                msgContentFrame.setOnClickListener {
                    msg.status = MessageStatus.DOWNLOADING
                    sendingProgress.visibility = View.VISIBLE
                    fileStatusText.setText(R.string.downloading)
                    // 下载文件

//                    ToastUtils.showShort("getToFile fail")
//                    sendingProgress.visibility = View.GONE
//
//                    msg.setDataPath(path)
//                    fileStatusText.setText(R.string.downloaded)
//                    msg.setStatus(MessageInfo.MSG_STATUS_DOWNLOADED)
//                    sendingProgress.visibility = View.GONE
//                    msgContentFrame.setOnClickListener { ToastUtils.showShort("文件路径:$path") }
                }
            }
        }

    }

}